//index.js
//获取应用实例
const app = getApp()

Page({
  data: {
    code: "",
    id: "",
    displaygmf: "none",
    gmficontype: "info",
    displayxsf: "none",
    xsficontype: "info",
    displaymx: "none",
    mxicontype: "info",
    header: null,
    items: null,
    vt: {
      text: "",
      fpdm: "",
      fphm: "",
      kprq: "",
      jym: "",
      gfmc: "",
      gfsbh: "",
      gfyhzh: "",
      gfdzdh: "",
      xfmc: "",
      xfsbh: "",
      xfyhzh: "",
      xfdzdh: "",
      je: "",
      se: "",
      jshjxx: "",
      jshjdx: "",
      items: []
    },
  },
  pageback: function() {
    // wx.navigateTo({
    //   url: '\index',
    // })
    wx.navigateBack({

    })
  },
  findHeaderById: function(id) {
    var item
    for(var x in this.data.header.fields){
      item = this.data.header.fields[x]
      if(item.name == id){
        return item.value
        break
      }
    }
  },
  analyItems: function (items) {
    var itemArray = []
    for (var x in items.items) {
      var item = {}
      for(var y in items.items[x].fields){
        var field = items.items[x].fields[y]
        if (field.name == 'xmmc'){
          item.xmmc = field.value
        }
        else if (field.name == 'xh') {
          item.xh = field.value
        }
        else if (field.name == 'dw') {
          item.dw = field.value
        }
        else if (field.name == 'sl') {
          item.sl = field.value
        }
        else if (field.name == 'dj') {
          item.dj = field.value
        }
        else if (field.name == 'je') {
          item.je = field.value
        }
        else if (field.name == 'rate') {
          item.rate = field.value
        }
        else if (field.name == 'se') {
          item.se = field.value
        }
      }
      itemArray.push(item)
    }

    this.setData({
      items:itemArray
    })
  },
  showgmfinfo: function() {
    this.setData({
      displaygmf: (this.data.displaygmf == "none") ? "block" : "none",
      gmficontype: (this.data.gmficontype == "info") ? "warn" : "info",
    })
  },
  showxsfinfo: function() {
    this.setData({
      displayxsf: (this.data.displayxsf == "none") ? "block" : "none",
      xsficontype: (this.data.xsficontype == "info") ? "warn" : "info",
    })
  },
  showmxinfo: function() {
    this.setData({
      displaymx: (this.data.displaymx == "none") ? "block" : "none",
      mxicontype: (this.data.mxicontype == "info") ? "warn" : "info",
    })
  },
  onLoad: function(options) {
    var that = this
    wx.getStorage({
      key: 'detail',
      success: function(res) {
        that.setData({
          header: res.data['data']['header'],
        })
        that.analyItems(res.data['data']['items'])
        that.setData({
          'vt.fpcc': that.findHeaderById('fpcc'),
          'vt.fpdm': that.findHeaderById('fpdm'),
          'vt.fphm': that.findHeaderById('fphm'),
          'vt.kprq': that.findHeaderById('kprq'),
          'vt.jym': that.findHeaderById('jym'),
          'vt.gfmc': that.findHeaderById('gfmc'),
          'vt.gfsbh': that.findHeaderById('gfsbh'),
          'vt.gfyhzh': that.findHeaderById('gfyhzh'),
          'vt.gfdzdh': that.findHeaderById('gfdzdh'),
          'vt.xfmc': that.findHeaderById('xfmc'),
          'vt.xfsbh': that.findHeaderById('xfsbh'),
          'vt.xfyhzh': that.findHeaderById('xfyhzh'),
          'vt.xfdzdh': that.findHeaderById('xfdzdh'),
          'vt.je': that.findHeaderById('je'),
          'vt.se': that.findHeaderById('se'),
          'vt.jshjdx': that.findHeaderById('jshjdx'),
          'vt.jshjxx': that.findHeaderById('jshjxx'),
        })
      }
    })
  }
})